/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
	TreeNode* head = nullptr;
	TreeNode* cur = nullptr;
	TreeNode* Convert(TreeNode* pRootOfTree) {
		if (!pRootOfTree) return nullptr;
		Convert(pRootOfTree->left);
		if (head == nullptr && cur == nullptr)
		{
			head = pRootOfTree;
			cur = pRootOfTree;
		}
		else
		{
			cur->right = pRootOfTree;
			pRootOfTree->left = cur;
			cur = pRootOfTree;
		}
		Convert(pRootOfTree->right);
		return head;
	}
};